package service

import (
	"context"
	"errors"
	__ "order_srv/basic/orderproto"
	"order_srv/handler/dao"
)

// CreateFence 创建围栏
func (s *Server) CreateFence(_ context.Context, in *__.CreateFenceReq) (*__.CreateFenceResp, error) {
	fence, err := dao.CreateFence(in)
	if err != nil {
		return nil, errors.New("创建围栏失败" + err.Error())
	}
	return &__.CreateFenceResp{
		Id: int64(fence.Id),
	}, nil
}

// UpdateFence 更新围栏
func (s *Server) UpdateFence(_ context.Context, in *__.UpdateFenceReq) (*__.UpdateFenceResp, error) {
	fence, err := dao.UpdateFence(in)
	if err != nil {
		return nil, errors.New("更新围栏失败" + err.Error())
	}
	return &__.UpdateFenceResp{
		Id: int64(fence.Id),
	}, nil
}

// DeletedFence 删除围栏
func (s *Server) DeletedFence(_ context.Context, in *__.DeletedFenceReq) (*__.DeletedFenceResp, error) {
	fence, err := dao.DeletedFence(in)
	if err != nil {
		return nil, errors.New("删除围栏失败" + err.Error())
	}
	return &__.DeletedFenceResp{
		Id: int64(fence.Id),
	}, nil
}

// ListFence 列表围栏
func (s *Server) ListFence(_ context.Context, in *__.ListFenceReq) (*__.ListFenceResp, error) {
	fence, err := dao.ListFence(in)
	if err != nil {
		return nil, errors.New("查询围栏列表失败" + err.Error())
	}
	return &__.ListFenceResp{
		List: fence,
	}, nil
}
